import { defineStore } from "pinia";
import pinia from "@/store";
export interface SettingState {
    theme: boolean;
}
export const useSettingStore = defineStore("Setting", {
    state: () => ({
        theme: true,
        title: [] as string[],
        routeName: [],
    }),
    getters: {},
    actions: {
        changeRouterName(name: string[]) {
            this.title = name;
            // console.log("this.title", this.title);
        },
        changeTheme(themeData, val) {
            // themeData从组件内传进来，这里直接修改主题
            themeData.value = val;
            this.theme = val;
            document.documentElement.setAttribute(
                "data-theme",
                val ? "light" : "dark",
            );
        },
        loadingSetting() {
            document.documentElement.setAttribute(
                "data-theme",
                this.theme ? "light" : "dark",
            );
        },
    },
    persist: {
        key: "setting",
        storage: localStorage,
        paths: ["theme"],
    },
});

export function useSettingStoreHook() {
    return useSettingStore(pinia);
}
